package com.htudata.alarm.controller;

import com.htudata.alarm.service.*;
import com.htudata.common.enums.RequestSeqEnum;
import com.htudata.common.enums.RequestStatusEnum;
import com.htudata.common.vo.ResponseResult;
import com.htudata.core.util.ResultGenerator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class AlarmController {

  @Autowired
  private AlarmCUDService alarmCUDService;
  
  @Autowired
  private AlarmShowService alarmShowService;

  @Autowired
  private AlarmDetailHistoryService alarmDetailHistoryService;
  
  @RequestMapping(value = {"/v1/live/alarms/{alarmId}/status"}, method = {RequestMethod.PUT})
  @ResponseBody
  public ResponseResult updateAlarmStatus(@PathVariable(required = true) long alarmId, @RequestParam(required = true) int type, @RequestParam(required = true) int status, @RequestParam(required = true) String a2) {
    try {
      return ResultGenerator.genResult(RequestSeqEnum.SEQ_001.getCode(), this.alarmCUDService
          .updateAlarmStatus(alarmId, type, status, a2));
    } catch (Exception e) {
      log.error("updateAlarmStatus", e);
      return ResultGenerator.genErrorResult(RequestSeqEnum.SEQ_001.getCode(), RequestStatusEnum.STATUS_503
          .getCode(), "暂无数据");
    } 
  }
  
  @RequestMapping(value = {"/v1/live/item/alarms"}, method = {RequestMethod.GET})
  public ResponseResult getAlarms(@RequestParam(required = true) String a2) {
    try {
      return ResultGenerator.genResult(RequestSeqEnum.SEQ_003.getCode(), this.alarmShowService
          .getAlarmList(a2));
    } catch (Exception e) {
      log.error("getAlarms", e);
      return ResultGenerator.genErrorResult(RequestSeqEnum.SEQ_003.getCode(), RequestStatusEnum.STATUS_503
          .getCode(), "暂无数据");
    } 
  }
  
  @RequestMapping(value = {"/v1/live/item/alarms/{triggerId}/details"}, method = {RequestMethod.GET})
  public ResponseResult getAlarmDetails(@PathVariable(required = true) long triggerId, @RequestParam(required = true) int type, @RequestParam(required = true) long days, @RequestParam(required = true) String a2) {
    try {
      return ResultGenerator.genResult(RequestSeqEnum.SEQ_003.getCode(), this.alarmDetailHistoryService
          .getAlarmHistoryList(String.valueOf(triggerId), type, days));
    } catch (Exception e) {
      log.error("getAlarmDetails", e);
      return ResultGenerator.genErrorResult(RequestSeqEnum.SEQ_003.getCode(), RequestStatusEnum.STATUS_503
          .getCode(), "暂无数据");
    } 
  }
}
